package com.thyme.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.thyme.system.dao.Iec61850IedDao;
import com.thyme.system.service.Iec61850IedService;
import com.thyme.system.vo.Iec61850IedVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author nana
 * @since 2021-03-24
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class Iec61850IedServiceImpl implements Iec61850IedService {
    private final Iec61850IedDao iec61850IedDao;

    @Override
    public int updateIED(Iec61850IedVo iedVo) {
        QueryWrapper<Iec61850IedVo> queryWrapper = new QueryWrapper<Iec61850IedVo>();
        queryWrapper.eq("ied_name",iedVo.getIedName());
        Iec61850IedVo iec61850IedVo =  iec61850IedDao.selectOne(queryWrapper);
        if(iec61850IedVo==null){
            iec61850IedDao.insertBy(iedVo);
        }else {
            iec61850IedDao.update(iedVo,queryWrapper);
            iedVo.setId(iec61850IedVo.getId());
        }
        return iedVo.getId();
    }
}
